<?php

namespace Sharks\Core\Make;

use Sharks\Core\AppContext;
use Sharks\Core\Module;
use Sharks\Core\Cfg\AppConfig;
use Sharks\Core\Http\Routing\Route;
use Sharks\Core\Make\Mode\DeployModeMaker;
use Sharks\Core\Make\Mode\DevelopmentModeMaker;
use Sharks\Core\Make\Mode\InitialModeMaker;
use Sharks\Core\Make\Mode\ServerModeMaker;
use Sharks\Core\Support\FrontEnd\Asset;
use Sharks\Core\Support\Storage\ArrayLoader;
use Sharks\Core\Support\Storage\StorageArrayUtils;

/**
 * Asset静态资源。
 * 依赖：
 * 		ModuleMaker
 */
class AssetsMaker extends Maker {
	
	/**
	 * 开发模式。即时读取指定位置文件
	 * @param  AppContext $app [description]
	 * @return [type]          [description]
	 */
	public function dev(AppContext $app) {
		Asset::init();
		
		foreach (Module::all() as $name => $module) {
			// 模块assets的指定位置
			if (file_exists($module->path()->resource . '/assets.php')) {
				require ($module->path()->resource . '/assets.php');
			}
		}
		
		if (file_exists($app->path()->app->source . "/Resource/assets.php")) {
			require ($app->path()->app->source . "/Resource/assets.php");
		}
		
	}
	
	/**
	 * 服务模式。直接加载预定义文件
	 * @param  AppContext $app [description]
	 * @return [type]          [description]
	 */
	public function server(AppContext $app) {
		$assets = ArrayLoader::load($app->path()->app->storage . '/assets.php', array());
		Asset::init($assets);
	}

	public function makers() {
		return array(ModuleMaker::class);
	}
}